<template>
  <div>
    <div style="margin-top: 1rem">
      <el-button icon="el-icon-document-add" type="primary" @click="handleAdd"
        >添加</el-button
      >
    </div>

    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="Id" width="180">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.Id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="ICP" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.ICP }}</span>
        </template>
      </el-table-column>
      <el-table-column label="公安备案号" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.recordno }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 对话框 -->
    <el-dialog title="公安备案信息" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="ICP" :label-width="formLabelWidth">
          <el-input v-model="form.ICP" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="公安备案号" :label-width="formLabelWidth">
          <el-input v-model="form.recordno" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirm">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 分页 -->
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pager.pageIndex"
        :page-size="pager.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pager.rowsTotal"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dialogFormVisible: false,
      pager: {
        pageIndex: 1,
        pageSize: 10,
        rowsTotal: 30,
      },
      tableData: [
        {
          Id: "1",
          ICP: "123456",
          recordno: "闽2541",
        },
        {
          Id: "2",
          ICP: "654123",
          recordno: "闽2541",
        },
        {
          Id: "3",
          ICP: "778654",
          recordno: "闽2545",
        },
      ],
      form: {
        id: 0,
        articleTypename: "",
      },
      formLabelWidth: "120px",
      //当前下标
      nowIndex: 0,
    };
  },
  methods: {
    //编辑
    handleEdit(index, row) {
      this.dialogFormVisible = true;
      this.form.id = row.id;
      this.form.ICP = row.ICP;
      this.form.recordno = row.recordno;
      //获取下标
      this.nowIndex = index;
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
    //添加
    handleAdd() {
      this.form.id = "";
      this.form.ICP = "";
      this.form.recordno = "";
      this.dialogFormVisible = true;
    },
    //确认
    confirm() {
      console.log(this.form);
      if (this.form.id == 0) {
        if (this.form.ICP.length > 0 && this.form.recordno.length > 0) {
          console.log(this.form);
        } else {
          this.$message({ type: "warning", message: "不能为空" });
        }
      } else {
      console.log(this.form);
      }
    },
    //大小更改(分页)
    handleSizeChange(val) {
      console.log(val);
    },
    //当前更改(分页)
    handleCurrentChange(val) {
      console.log(val);
    },
  },
};
</script>

<style>
</style>